package com.infore.airsupervise.adapter;

import com.beardedhen.androidbootstrap.AwesomeTextView;
import com.beardedhen.androidbootstrap.BootstrapText;
import com.beardedhen.androidbootstrap.api.defaults.DefaultBootstrapBrand;
import com.beardedhen.androidbootstrap.font.FontAwesome;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.infore.airsupervise.R;
import com.infore.airsupervise.app.StatusConst;
import com.infore.airsupervise.bean.MissionE;
import com.infore.airsupervise.utils.DateUtil;

import java.util.List;

/**
 * @features: 任务列表item适配器
 * @author: WuTao
 * @date: 2017/5/9 11:31
 */
public class MissionItemAdapter extends BaseQuickAdapter<MissionE,BaseViewHolder>{
    private String currentTime;

    public MissionItemAdapter(int layoutResId, List<MissionE> data) {
        super(layoutResId, data);
        currentTime = DateUtil.getCurrentDateStr(true);
    }

    @Override
    protected void convert(BaseViewHolder helper, MissionE item) {
        helper.setText(R.id.tv_mission_title, item.getTitle());
        AwesomeTextView tv_status = helper.getView(R.id.tv_mission_status);
        BootstrapText.Builder builder = new BootstrapText.Builder(mContext);
        if(item.getMissionStatus()== StatusConst.MISSION_STATUS_EXAMINE ||
                (item.getMissionStatus() == StatusConst.MISSION_STATUS_FINISH && item .getIsApproved() == 1)){ //完成状态
            builder.addFontAwesomeIcon(FontAwesome.FA_CHECK_CIRCLE_O);
            tv_status.setBootstrapBrand(DefaultBootstrapBrand.SUCCESS);
            helper.setText(R.id.tv_mission_content , "完成日期："+item.getLastTime());
        }else {  //未完成状态
            builder.addFontAwesomeIcon(FontAwesome.FA_CLOCK_O);
            tv_status.setBootstrapBrand(DefaultBootstrapBrand.WARNING);
            String endtime = DateUtil.toLongDate(item.getLastTime());
            long time = DateUtil.compareDate(endtime,currentTime);
            if(time>0){ //判断过期状态
                helper.setText(R.id.tv_mission_content, "截止日期：" + item.getLastTime());
            }else{
                helper.setText(R.id.tv_mission_content, "过期：" + Math.abs(time/DateUtil.TIME_DAY)+" 天")
                        .setTextColor(R.id.tv_mission_content,R.color.red_icon);
            }
        }
        tv_status.setBootstrapText(builder.build());

    }
}
